﻿@model CRF
@{
    ViewBag.Title = "添加病例报告";
    Layout = "~/Views/Shared/Master.cshtml";
}
@{Html.Telerik().Window().Name("CRFAddSelfWindow").Title("添加病例报告").HtmlAttributes(new { @class = "ContentWindow" })
    .Buttons(buttons => buttons.Clear())
    .Content(
@<text>
@{using (Ajax.BeginForm<CRFController>(c => c.CRFAdd(null),
    new AjaxOptions { OnBegin = "BeforeSend", OnSuccess = "OnSuccess", OnFailure = "OnError" }))
  {
<table>
    <tr>
        <th>医院编号</th>
        <td>
            @Html.DisplayFor(model => model.HospitalCode)
            @Html.HiddenFor(model=>model.HospitalCode)
        </td>
    </tr>
    <!--<tr>
        <th>病例序号</th>
        <td>@Html.TextBoxFor(model => model.CrfCode)</td>
    </tr>-->
    <tr>
        <th>研究单位</th>
        <td>
            @Html.DisplayFor(model => model.Hospital.Name)
            @Html.HiddenFor(model => model.HospitalID)
        </td>
    </tr>
    <tr>
        <th>研究者</th>
        <td>
            @Html.DisplayFor(model => model.Researcher.RealName)
            @Html.HiddenFor(model => model.ResearcherID)
        </td>
    </tr>
    <tr>
        <th>开始时间</th>
        <td>@Html.DateEditorFor(model => model.StartTime)</td>
    </tr>
    <tr>
        <th><span style="color:red;">*</span>身份证号</th>
        <td>@Html.TextBoxFor(model => model.Patient.IDCard)</td>
        <th><span style="color:red;visibility:hidden;" id="IDCard_alert">身份证号不能为空</span></th>
    </tr>
    <tr>
        <th><span style="color:red;">*</span>社保号</th>
        <td>@Html.TextBoxFor(model => model.Patient.SocialID)</td>
        <th><span style="color:red;visibility:hidden;" id="SocialID_alert">社保号不能为空</span></th>
    </tr>
    <tr>
        <th><span style="color:red;">*</span>姓名</th>
        <td>@Html.TextBoxFor(model => model.Patient.Name)</td>
        <th><span style="color:red;visibility:hidden;" id="Name_alert">姓名不能为空</span></th>
    </tr>
    <tr>
        <th>性别</th>
        <td>@Html.GenderEditorFor(model => model.Patient.Gender)</td>
    </tr>
    <tr>
        <th>民族</th>
        <td>@Html.TextBoxFor(model => model.Patient.Nationality)</td>
    </tr>
    <tr>
        <th>就诊科室</th>
        <td>@Html.TextBoxFor(model => model.Patient.TreatDepart)</td>
    </tr>
    <tr>
        <th>生日</th>
        <td>@Html.DateEditorFor(model => model.Patient.Birthday)</td>
    </tr>
    <tr>
        <th>单位</th>
        <td>@Html.TextBoxFor(model => model.Patient.Company)</td>
    </tr>
    <tr>
        <th>工种</th>
        <td>@Html.TextBoxFor(model => model.Patient.JobKind)</td>
    </tr>
    <tr>
        <th><span style="color:red;">*</span>电话</th>
        <td>@Html.TextBoxFor(model => model.Patient.Phone)</td>
        <th><span style="color:red;visibility:hidden;" id="Phone_alert">电话不能为空</span></th>
    </tr>
    <tr>
        <th>职业</th>
        <td>@Html.TextBoxFor(model => model.Patient.Job)</td>
    </tr>
    <tr>
        <th>地址</th>
        <td>@Html.TextBoxFor(model => model.Patient.Address)</td>
    </tr>
    <tr>
        <th>出生地</th>
        <td>@Html.TextBoxFor(model => model.Patient.BirthPlace)</td>
    </tr>
    <tr>
        <th>婚姻状况</th>
        <td>@Html.MarriageEditorFor(model => model.Patient.Marriage)</td>
    </tr>
</table>
<input type="submit" onclick="validat();" value="提交" />
  }
}
</text>)
    .Render();
}
@{Html.Telerik().Window().Modal(true).Visible(false)
    .Name("adding").Title("系统提示")
    .Buttons(buttons => buttons.Clear())
    .ClientEvents(window => window.OnOpen("OnAddingOpen"))
    .Content(
@<text>
正在添加，请稍后...
</text>)
    .Render();
}
@{Html.Telerik().Window().Modal(true).Visible(false)
    .Name("addError").Title("系统提示")
    .Buttons(buttons => buttons.Close())
    .ClientEvents(window => window.OnOpen("OnAddErrorOpen"))
    .Content(
@<text>
出现错误，请重试！
</text>)
    .Render();
}
<script type="text/javascript">
    function OnAddingOpen() {
        $("#adding").data("tWindow").center();
    }
    function OnAddErrorOpen() {
        $("#addError").data("tWindow").center();
    }
    function BeforeSend() {
        $("#adding").data("tWindow").open();
    }
    function OnSuccess(data) {
        if (data.ID) {
            var url = "@(Url.Action<CRFController>(c => c.CRFDetail(Guid.Empty)))";
            url = url.replace("@Guid.Empty", data.ID);
            window.location = url;
        } else {
            $("#addError").data("tWindow").open();
            $("#adding").data("tWindow").close();
        }
    }
    function OnError(){
        $("#addError").data("tWindow").open();
        $("#adding").data("tWindow").close();
    }
    function validat() {
        var isfalse = "";
        var valueName = Patient_Name.value;
        var valueIDCard = Patient_IDCard.value;
        var valuePhone = Patient_Phone.value;
        var valueSocialID = Patient_SocialID.value; 
        if (valueIDCard == "") {
             IDCard_alert.style.visibility = "visible";
             isfalse = "false";
         }
        else {
             IDCard_alert.style.visibility = "hidden";
         }
        if (valueName=="") {
            Name_alert.style.visibility = "visible";
            isfalse = "false";
        }
        else {
            Name_alert.style.visibility = "hidden";
        }
        if (valuePhone == "") {
            Phone_alert.style.visibility = "visible";
            isfalse = "false";
        }
        else {
            Phone_alert.style.visibility = "hidden";
        }
        if (valueSocialID == "") {
            SocialID_alert.style.visibility = "visible";
            isfalse = "false";
        }
        else {
            SocialID_alert.style.visibility = "hidden";
        }
        if (isfalse == "false") {
            return false;
        }
    }
</script>